﻿// ROBoundary3d.hpp
#ifndef _ROBoundary3d_H_
#define _ROBoundary3d_H_

#include "ThreeDApi.hpp"

#include <vtkProp3D.h>
#include <vtkSmartPointer.h>
#include <vtkPoints.h>
#include <vtkCellArray.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkAppendPolyData.h>
#include <vtkLookupTable.h>
#include <vtkDoubleArray.h>
#include <vtkCamera.h>
#include <vtkRenderer.h>
#include <vtkProperty.h>
#include <vtkPointData.h>
#include <vtkTransform.h>
#include <vtkRenderer.h>
#include <vtkPoints.h>

#include <QVector>

namespace NS3d {

#define M_PI 3.1415926


    class _3DAPI ROBoundary3d : public vtkProp3D
    {
    public:
        typedef struct BDPoint {
            double x;
            double y;
            double z;
        };
    public:
        static ROBoundary3d* New();
        vtkTypeMacro(ROBoundary3d, vtkProp3D);

        // 设置参数
        void setBaseRadius(double size);
        void setRotationColor(double r, double g, double b);
        void setDisplacementColor(double r, double g, double b);
        void setFixedPoints(vtkPoints* points);

        // 获取数据和颜色
        vtkSmartPointer<vtkPolyData> getMergedCones();
        double* getColorRotation();
        double* getColorDisplacement();

        // 构建
        void Build();
        // 获取边界
        double* GetBounds() override;
        // 添加到渲染器
        void GetActors(vtkPropCollection* collection) override;
        // 渲染方法
        int RenderOpaqueGeometry(vtkViewport* viewport) override;
        int RenderTranslucentPolygonalGeometry(vtkViewport* viewport) override;
        int HasTranslucentPolygonalGeometry() override;
        void ReleaseGraphicsResources(vtkWindow* win) override;

    protected:
        ROBoundary3d();
        ~ROBoundary3d() override;
        vtkSmartPointer<vtkPolyData> xBuild(BDPoint bdp, double h, const double direction[3]);
        QVector<vtkSmartPointer<vtkPolyData>> createBC(BDPoint bdp);

        // 更新变换
        void UpdateTransform();

    private:
        ROBoundary3d(const ROBoundary3d&) = delete;
        void operator=(const ROBoundary3d&) = delete;

        // 参数
        double base_radius;
        double height;
        double color_rotation[3];
        double color_displacement[3];
        QVector<BDPoint> fixed_points;

        // 内部组件
        vtkSmartPointer<vtkAppendPolyData> AppendFilter;
        vtkSmartPointer<vtkLookupTable> LookupTable;
        vtkSmartPointer<vtkPolyDataMapper> Mapper;
        vtkSmartPointer<vtkActor> Actor;
    };

} // namespace NS3d

#endif // _ROBoundary3d_H_